package com.lizhi.menu.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.lizhi.menu.common.response.Result;
import com.lizhi.menu.domain.TOrder;
import com.lizhi.menu.service.ITOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 订单Controller
 *
 * @author lizhi
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/system/order")
@Api(tags = "订单管理")
public class TOrderController {
    @Autowired
    private ITOrderService tOrderService;

    /**
     * 查询订单列表
     */
    @GetMapping("/list")
    @ApiOperation("查询订单列表")
    public Result list(TOrder tOrder) {

        List<TOrder> list = tOrderService.selectTOrderList(tOrder);
        return Result.ok(list);
    }

    /**
     * 查询订单列表
     */
    @GetMapping("/my")
    @ApiOperation("查询订单列表")
    public Result my(TOrder tOrder) {
        tOrder.setUserId(StpUtil.getLoginId().toString());
        List<TOrder> list = tOrderService.selectTOrderList(tOrder);
        return Result.ok(list);
    }

    /**
     * 获取订单详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取订单详细信息")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.ok(tOrderService.selectTOrderById(id));
    }

    /**
     * 新增订单
     */
    @PostMapping
    @ApiOperation("新增订单")
    public Result add(@RequestBody TOrder tOrder) {
        tOrder.setUserId(StpUtil.getLoginId().toString());
        return Result.ok(tOrderService.insertTOrder(tOrder));
    }

    /**
     * 修改订单
     */
    @PutMapping
    @ApiOperation("修改订单")
    public Result edit(@RequestBody TOrder tOrder) {
        return Result.ok(tOrderService.updateTOrder(tOrder));
    }

    /**
     * 删除订单
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("删除订单")
    public Result remove(@PathVariable Long[] ids) {
        return Result.ok(tOrderService.deleteTOrderByIds(ids));
    }
}
